#ifndef CTRADEBYMARKETDATA_H
#define CTRADEBYMARKETDATA_H
#include <QString.h>
#include "UFX/tool.h"
#include "UFX/analyStr.h"

#define  MSGCENTER_FUNC_HEART		 620000                                           //消息中心心跳功能号
#define  MSGCENTER_FUNC_REG			 620001                                           //消息中心订阅功能号
#define  MSGCENTER_FUNC_REG_CANCLE   620002                                           //消息中心取消订阅功能号
#define  MSGCENTER_FUNC_SENDED		 620003                                           //消息中心主推功能号

#define MSG_UFX_ISSUE_TYPE_HQ          33100
#define MSG_UFX_ISSUE_TYPE_REPORT      33101
#define MSG_UFX_ISSUE_TYPE_HQ_ARBIT    33102
#define MSG_UFX_ISSUE_TYPE_EXCH_STATUS 33105

#define szSTR 1024

struct ConfigInfo
{
    char   c_TestMode;
    int    l_SleepSec;//间隔N毫秒
    char   m_strExchange[4];//交易所
    char   m_strCode[30];//需要测试的合约
    char   c_BS;//买卖方向
    int    l_Amount;//委托数量
    char   c_PriceType;//委托价格方式(0：涨跌停；1：最新价；2：对盘价；)
    double en_Price;//委托价格(如果大于0，则直接按指定价格委托，否则根据类型下单)
    int    l_ExchangeTime;//根据交易所行情时间来下单(eg:144510500,14点45分10秒500毫秒)
    int    l_EntrustAmount;//交易次数
};

class CTraderRequestMode;
class CMdRequestMode;

class CQueryInfo
{
private:
    static CThreadSafeValue currRequestId;
    static int NewRequestId();
};


class CTradeByMarketData{

public:
    CTradeByMarketData();
    ~CTradeByMarketData();
public:
    //初始化
    int Init(QString UserName,QString Password);
    //等待结束运行
    int Join();

    CTraderRequestMode* GetTraderRequest();
    CMdRequestMode*     GetMdRequest();
    bool                SubscribeMarketData(QString ContractName);
    bool                OrderInsert(const char* exch_type, const char* contract_code, char c_bs, char c_direction, char c_hedge, int l_entrust_amount, double en_entrust_price,const char* entrust_prop);
	bool				CancelOrder(const char* exch_type, int entrust_no);

    bool                QryTradingAccount();
    bool				QryContractsInfo(QString contractname, const char* positionstr);
    bool				QryHoldsInfo(QString positionstr);
    //查询合约保证金信息
    bool                QryInstrumentMarginRate(QString contractcode,const char* position_str);

    bool                QryTradeRecs(QString positionstr);
    //339853 查询期货历史成交信息
    bool                QryHisTradeRecs(QString start,QString end,QString positionstr);

    inline const char* GetOpStation()
    {
        return m_opStation.c_str();
    }
    bool GetDebug()
    {
        return b_Debug;
    }

    string GetUserID(){return m_strFundAccount;}


    //暂时增加
    bool   b_SendOrder;
    double en_last_price;
    int    l_update_time;
    int    l_trade_amount;
private:
    CTraderRequestMode* lp_TraderRequest;
    CMdRequestMode* lp_MDRequest;

    string m_localip;
    string m_localMac;
    string m_opStation;
    string m_strTraderAddr;
    string m_strMdAddr;
    string m_strBranchNo;
    string m_strFundAccount;
    string m_strPassWord;
    char   c_EntrustType;
    bool   b_Debug;
};

#endif // CTRADEBYMARKETDATA_H
